package com.fetch;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import android.os.AsyncTask;


public class FetchXML extends AsyncTask<Object, Boolean, List<List<String>>> {
	
	private String url;
	private String tagname;
	private String[] fieldnames;
	
	public FetchXML(String url, String tagname, String[] fieldnames) {
		this.url = url;
		this.tagname = tagname;
		this.fieldnames = fieldnames;
	}

	@Override
	protected List<List<String>> doInBackground(Object... params) {
		InputStream stream = null;
		
		try {	

			URL urlt = new URL(url);
			HttpURLConnection conn = (HttpURLConnection) urlt.openConnection();
			conn.setReadTimeout(10000 /* milliseconds */);
			conn.setConnectTimeout(15000 /* milliseconds */);
			conn.setRequestMethod("GET");
			conn.setDoInput(true);
			conn.connect();
			stream = conn.getInputStream();

			} catch (MalformedURLException e) {
			// 	TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
			// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		
        return ReadXMLFile.parse(stream, tagname, fieldnames);
	}



}